import 'package:chat_app_project/dao/demand_dao.dart';
import 'package:chat_app_project/util/toast_util.dart';
import 'package:flutter/material.dart';
import 'package:getwidget/components/button/gf_button.dart';
import 'package:getwidget/components/text_field/gf_text_field.dart';

class Publish extends StatefulWidget {
  const Publish({Key? key}) : super(key: key);

  @override
  State<Publish> createState() => _PublishState();
}

class _PublishState extends State<Publish> {
  TextEditingController titleController = TextEditingController();
  TextEditingController amountController = TextEditingController();
  TextEditingController locationController = TextEditingController();
  TextEditingController detailsController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('发布'),
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            GFTextField(
              controller: titleController,
              decoration: const InputDecoration(
                  border: InputBorder.none, hintText: '标题输这里...'),
            ),
            SizedBox(height: 16.0),
            GFTextField(
              controller: amountController,
              decoration: const InputDecoration(
                  border: InputBorder.none, hintText: '金额输这里...'),
            ),
            SizedBox(height: 16.0),
            GFTextField(
              controller: detailsController,
              decoration: const InputDecoration(
                  border: InputBorder.none, hintText: '详情输这里...'),
            ),
            SizedBox(height: 16.0),
            GFButton(
              child: Text('发布'),
              onPressed: () {
                if (titleController.text.isEmpty ||
                    amountController.text.isEmpty ||
                    detailsController.text.isEmpty) {
                  ToastUtil.toast("参数不能为空");
                  return;
                }
                DemandDao.create({
                  "title": titleController.text,
                  "money": amountController.text,
                  "content": detailsController.text,
                  "pics": ["https://img1.baidu.com/it/u=2252911813,3770214976&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=750"]
                }).then((value) {
                  Navigator.of(context).pop();
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
